﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MugenInjection.Interface.Components;

namespace MugenInjectionTest
{
    public static class TestUtils
    {
        public static void RemoveAllConverters(this IBindingActivatorComponent component)
        {
            foreach (var source in component.Converters.ToArray())
            {
                component.RemoveConverter(source);
            }
        }

        [DebuggerStepThrough()]
        public static void Catch<T>(Action action) where T : Exception
        {
            Catch<T>(action, string.Empty);
        }

        [DebuggerStepThrough()]
        public static void Catch<T>(Action action, string message) where T : Exception
        {
            //error test
            bool isCatch = false;
            try
            {
                action();
            }
            catch (T)
            {
                isCatch = true;
            }
            Assert.IsTrue(isCatch, message);
        }

        [DebuggerStepThrough()]
        public static void IsInstancesOfType<T>(IEnumerable objects, int count)
        {
            Assert.AreEqual(objects.Cast<object>().Count(), count);
            Assert.IsTrue(objects.Cast<object>().All(c => c.GetType() == typeof(T)));
        }

        [DebuggerStepThrough()]
        public static void IsContainObjects(IEnumerable objects, params object[] objs)
        {
            foreach (var o in objs)
            {
                Assert.IsTrue(objects.Cast<object>().Contains(o));
            }
        }

#if !NETFX_CORE
        public static Type GetTypeInfo(this Type type)
        {
            return type;
        }

        public static Type AsType(this Type type)
        {
            return type;
        }
#endif

    }


}

namespace System.CodeDom.Compiler
{
    [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
    public sealed class GeneratedCodeAttribute : Attribute
    {
        private readonly string tool;
        private readonly string version;

        public GeneratedCodeAttribute(string tool, string version)
        {
            this.tool = tool;
            this.version = version;
        }

        public string Tool
        {
            get { return this.tool; }
        }

        public string Version
        {
            get { return this.version; }
        }
    }
}